﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlExtractor.Config;


namespace HtmlExtractor
{
    public class Extractor
    {
        public Extractor()
        {

        }
        public string ExtractorConfigUri;
        public Extractor(string extractorConfigUri)
        {
            ExtractorConfigUri = extractorConfigUri;
        }
        public bool TryGetResult(ParserContext context,out PageResult pageResult)
        {
            ExtractorConfig config = new ExtractorConfig(ExtractorConfigUri);
            pageResult = null;
            string domainUri;
            if (config.TryGetDomainConfig(context.ParseUri, out domainUri))
            {
                LinqPageConfigCreater ruleCreater = new LinqPageConfigCreater(domainUri);
                PageConfig pageRule;
                if (ruleCreater.TryCreatePageConfig(context.ParseUri, out pageRule))
                {
                    pageResult = pageRule.GetParseResult(context);
                    return true;
                }
                else
                {                   
                    return false;
                }
            }
            else
                return false;
            
            
        }

    }
}
